<template>
	<view class="content">
		<view class="picker">
			<view class="picker_text">
				<image v-if="index !== ''" class="filter" src="/static/image/filter1.png"></image>
				<image v-else class="filter" src="/static/image/filter.png"></image>
				<view :class="{active:index!==''}">年度：</view>
			</view>
			<picker @change="bindPickerChange" :value="index" :range="yearList">
				<view class="uni-input">{{ selectYear || '请选择'}}</view>
			</picker>
			<view style="color: #3E9CF9;margin-left: 40upx;" @click="clearChange">清空</view>
		</view>
		<empty v-if="dataRecord.length == 0"></empty>
		<view style="margin-top: 100upx;">
			<view class="list-box" v-for="(item,index) in dataRecord" :key="index" @click="goToVerify(item)">
				<view class="list-title">
					<view class="title-text">{{item.cycle}}年度</view>
					<view v-if="item.verificationState == '0' || item.verificationState == '2'">
						{{item.verificationState == "0" ? "重新核验" : "开始核验"}}<text class="yticon icon-you title-icon"></text>
					</view>
				</view>
				<view class="list-cell">
					<view class="list-cell-item">
						<view class="item-title">申请人</view>
						<view class="item-info">{{item.name}}</view>
					</view>
					<view class="list-cell-item">
						<view class="item-title">身份证号</view>
						<view class="item-info">{{item.idCard}}</view>
					</view>
					<view class="list-cell-item">
						<view class="item-title">核验状态</view>
						<view class="item-info">{{getVerificationState(item.verificationState)}}</view>
					</view>
					<view class="list-cell-item">
						<view class="item-title">核验项目</view>
						<view class="item-info">
							<view v-for="(category,categoryIndex) in item.businessCategory" :key="categoryIndex">
								{{category.businessCategory}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<uni-load-more :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import empty from "@/components/empty";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			empty
		},
		data() {
			return {
				userId: "",
				yearList: [],
				selectYear: "",
				page: 1,
				total: 0,
				index: null,
				dataRecord: [],
				ownerInfo: {
					name: "",
					idCard: ""
				},
				loadingType: "more"
			}
		},
		onLoad(option) {
			let userInfo = uni.getStorageSync("userInfo")
			if (userInfo && userInfo.userUuid) {
				this.userId = userInfo.userUuid
			}
			this.getYearList()
			this.getRecordData()
		},
		onReachBottom() {
			if (this.loadingType === 'more') {
				this.page = this.page + 1;
				this.getRecordData()
			}
		},
		methods: {
			getRecordData() {
				this.loadingType = "loading"
				let params = {
					startAssigneeId: this.userId,
					cycle: this.selectYear,
					page: this.page,
					pageSize: 5
				}
				this.$api.request.verificationQueryConsumer(params, (res) => {
					if (res.code == 200) {
						this.total = res.data.total;
						if (res.data.vos != null) {
							this.dataRecord = this.dataRecord.concat(res.data.vos);
						}
						if(this.dataRecord.length >= this.total){
							this.loadingType = "noMore"
						}else{
							this.loadingType = "more"
						}
					} else {
						this.$api.msg("查询失败")
					}
				})
			},
			goToVerify(item) {
				if (item) {
					this.ownerInfo = {
						name: item.name,
						idCard: item.idCard
					}
					if (item.verificationState == "0" || item.verificationState == "2") {
						uni.navigateTo({
							url: '/package_biz/pages/declare/verification/baidu?ownerInfo=' + JSON.stringify(this.ownerInfo)
						})
					} else if (item.verificationState == "5") {
						this.$api.msg("该申请已失效，请重新提交申请")
					}
				}
			},
			bindPickerChange(e) {
				this.index = e.detail.value
				this.selectYear = this.yearList[this.index]
				this.dataRecord = [];
				this.getRecordData()
			},
			getYearList() {
				let nowYear = new Date().getFullYear();
				this.yearList = [];
				for (let i = 0; i < 10; i++) {
					this.yearList.push(nowYear - i)
				}
			},
			clearChange() {
				this.selectYear = "";
				this.index = null;
				this.page = 1;
				this.dataRecord = [];
				this.getRecordData()
			},
			getVerificationState(state) {
				let result = "";
				switch (state) {
					case "0":
						result = "不通过";
						break;
					case "1":
						result = "通过";
						break;
					case "2":
						result = "未核验";
						break;
					case "5":
						result = "已失效";
						break;
				}
				return result;
			},
		}
	}
</script>

<style lang='scss'>
	page {
		background: $page-color-base
	}

	.content {
		position: relative;
	}

	.list-box {
		margin: 30upx;
		background-color: white;
		border-radius: 20upx;
	}

	.list-cell {
		padding: 30upx;
		background-color: white;

		.list-title {
			height: 90upx;
			line-height: 90upx;
			font-size: 30upx;
			font-weight: bolder;
		}

		.list-bottom {
			height: 90upx;
			line-height: 90upx;
		}

		.list-cell-item {
			padding: 24upx 0;
			display: flex;
			flex-direction: row;
			justify-content: space-between;

			.item-title {
				font-size: 28upx;
				font-weight: border;
				text-align: left;
				margin-left: 20upx;
			}

			.item-info {
				font-size: 24upx;
				text-align: right;
				margin-right: 20upx;
			}
		}
	}

	.list-title {
		background-color: white;
		padding-left: 40upx;
		height: 90upx;
		line-height: 90upx;
		border-bottom: 1px solid #e9eef5;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		letter-spacing: 2upx;

		.title-text {
			font-size: 32upx;
			font-weight: bolder;
			width: 75%;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.title-icon {
			margin-right: 26upx;
			font-size: 30upx;
			font-weight: bold;
		}
	}

	.picker {
		background-color: white;
		padding: 20upx;
		display: flex;
		align-items: center;
		color: #7A7A7A;
		font-size: 30upx;
		position: fixed;
		width: 100%;
		top: 0;
		z-index: 99;
	}

	.active {
		color: #3E9CF9;
	}

	.picker_text {
		display: flex;
		align-items: center;
	}

	.filter {
		width: 34upx;
		height: 34upx;
		margin-right: 8upx;
	}
</style>
